package org.mozhu.mboot.admin.system.privilege.service;

import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.mozhu.mboot.core.data.support.BaseTreeableService;
import org.mozhu.mboot.admin.system.privilege.entity.Permission;
import org.mozhu.mboot.admin.system.privilege.repository.PermissionRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;

/**
 * 权限 - 业务层实现类
 * 
 * @author mozhu
 */
@Transactional
@Service(value = "permissionService")
public class PermissionServiceImpl extends BaseTreeableService<Permission, Long> implements PermissionService {

	protected PermissionRepository getBaseRepository() {
		return (PermissionRepository) baseRepository;
	}

	/**
	 * 获取可用的权限列表
	 * 
	 * @param permissionIds
	 * @return
	 */
	@Override
	public List<Permission> findAvailablePermissions(Collection<Long> permissionIds) {
		if (CollectionUtils.isEmpty(permissionIds)) {
			return Lists.newArrayList();
		}
		return this.getBaseRepository().findAvailablePermissions(permissionIds);
	}

	@Override
	public List<Long> findDefaultPermissionIds() {
		return this.getBaseRepository().findDefaultPermissionIds();
	}

	@Override
	public List<Permission> findDefaultPermissions() {
		return this.getBaseRepository().findDefaultPermissions();
	}

}
